package main

import (
	"fmt"
	"net/http"
	"time"

	"golang.org/x/net/websocket"
)

func main() {
	mux := &http.ServeMux{}
	mux.Handle("/api", websocket.Handler(func(c *websocket.Conn) {
		for n := 0; n < 10; n++ {
			c.Write([]byte(fmt.Sprintf("%d", n)))
			time.Sleep(1 * time.Second)
		}
	}))
	svr := &http.Server{
		Addr:    ":3000",
		Handler: mux,
	}
	svr.ListenAndServe()
}
